Instance Methods

The following instance methods are available globally.

  • Note that T is not Equatable, so this uses identity equality.

    Declaration

    Swift

    @warn_unused_result
    public func indexOf(element: T) -> Int?
  • Note that T is not Equatable, so this uses identity equality.

    Declaration

    Swift

    mutating public func remove(value: T)
  • Send a command to the remote lane to which this Downlink is connected.

    Declaration

    Swift

    func command(body body: SwimValue) -> <<error type>>

    Return Value

    A BFTask representing the command. This will succeed with nil result when the server acks the command, or it will fail if the command could not be sent.

  • Note that this is asynchronous, but there’s no task to track success. This is because you might never get an ack for this request, e.g. if the server goes down before the request is handled, and there’s no tracking inside this SDK for that. We could add that, but it hasn’t been necessary and this way we avoid lots of complexity.

    Declaration

    Swift

    func sendSyncRequest()
  • Unregister this Downlink so that it no longer receives events. If this was the only active link to a particular lane, then the link will be unlinked.

    Declaration

    Swift

    func close()
  • Declaration

    Swift

    func addDelegate(delegate: DownlinkDelegate)

    Parameters

    delegate

    Will be weakly referenced by this Downlink.

  • Declaration

    Swift

    private func runTask(query: Insert) -> <<error type>>

    Return Value

    A task which will have rowId: NSNumber as the result.

  • Declaration

    Swift

    private func runQueryTask<T : AnyObject>(query: QueryType, f: Row -> T?) -> <<error type>>

    Return Value

    A task which will have [T] as the result.

  • Declaration

    Swift

    private func runTasks(statements: [String], _ bindings: Binding?...) -> <<error type>>

    Return Value

    A task which will have [Statement] as the result.

  • May only be called under objc_sync_enter(self)

    Declaration

    Swift

    private func openAsync_(lane: SwimUri, _ persistenceType: PersistenceType) -> <<error type>>
  • Declaration

    Swift

    public func loadListContents(lane: SwimUri) -> <<error type>>

    Return Value

    A task that will have a NSArray as the result. The contents of that array will SwimRecord instances if the value is a record. TODO: Unimplemented: returning primitive types.

  • May only be called under objc_sync_enter(self)

    Declaration

    Swift

    private func setFileSize(url: NSURL, _ size: UInt64) -> <<error type>>
  • Declaration

    Swift

    private func runTask(statement: String, _ bindings: Binding?...) -> <<error type>>

    Return Value

    A task which will have a Statement as the result.

  • Unlinks all downlinks registered with the scope.

    Declaration

    Swift

    func close()
  •    let chat = client.scope(node: "ws://swim.example.com/chat/public")
       let chatRoom = chat.scope(lane: "chat/room")
    

    Declaration

    Swift

    func scope(lane lane: SwimUri) -> <<error type>>

    Return Value

    A new LaneScope bound to the given lane URI of the service to which this scope is bound.

  • Sends a command to the remote lane to which this scope is bound.

       let chat = client.scope(node: "ws://swim.example.com/chat/public", lane: "chat/room")
       chat.command(body: "Hello, world!")
    

    Declaration

    Swift

    func command(body body: SwimValue) -> <<error type>>
  • Unlinks all downlinks registered with the scope.

    Declaration

    Swift

    func close()
  • Declaration

    Swift

    func syncList(properties properties: LaneProperties, objectMaker: (SwimValue -> SwimModelProtocolBase?)) -> <<error type>>

    Parameters

    objectMaker

    A callback that will construct a model object given the SwimValue received from the server. This effectively tells the ListDownlink what type of model object should be constructed when a new value is received.

  • Must be called under objc_sync_enter(self)

    Declaration

    Swift

    private func startNetworkMonitor(host: String)
  • Must be called under objc_sync_enter(self)

    Declaration

    Swift

    private func startNetworkMonitorIfNecessary() -> SwimSwift.SwimNetworkConditionMonitor.ServerMonitor
  • Declaration

    Swift

    private func createValueDownlinks(node node: SwimUri, lane: SwimUri, properties: LaneProperties, objectMaker: (SwimValue -> SwimModelProtocolBase?)) -> <<error type>>

    Return Value

    The RemoteDownlink that’s actually connected to the server, and the Downlink that is to be returned to the caller. If this request is for a transient lane then these two will be equal, otherwise the second Downlink will impose the requested persistence.

  • Declaration

    Swift

    private func createListDownlinks(node node: SwimUri, lane: SwimUri, properties: LaneProperties, objectMaker: (SwimValue -> SwimModelProtocolBase?)) -> <<error type>>

    Return Value

    The RemoteDownlink that’s actually connected to the server, and the Downlink that is to be returned to the caller. If this request is for a transient lane then these two will be equal, otherwise the second Downlink will impose the requested persistence.

  • Declaration

    Swift

    private func createMapDownlinks(node node: SwimUri, lane: SwimUri, properties: LaneProperties, objectMaker: (SwimValue -> SwimModelProtocolBase?), primaryKey: SwimModelProtocolBase -> SwimValue) -> <<error type>>

    Return Value

    The RemoteDownlink that’s actually connected to the server, and the Downlink that is to be returned to the caller. If this request is for a transient lane then these two will be equal, otherwise the second Downlink will impose the requested persistence.

  • Must be called under objc_sync_enter(self).

    Declaration

    Swift

    private func unregisterNode(node: SwimUri) -> <<error type>>
  • Must be called under objc_sync_enter(self).

    Declaration

    Swift

    private func unregisterLane(node: SwimUri, _ lane: SwimUri) -> <<error type>>
  • Will be called whenever commands are received that will change MapDownlink.objects, and before those commands are processed.

    In other words, this indicates the start of a batch of calls to swimMapDownlink(:did{Set,Remove,Update}:forKey:) or swimMapDownlinkDidRemoveAll(:objects:).

    Declaration

    Swift

    func swimMapDownlinkWillChange(downlink: MapDownlink)
  • Will be called after a batch of changes to MapDownlink.objects has been processed.

    In other words, this indicates the end of a batch of calls to swimMapDownlink(:did{Set,Remove,Update}:forKey:) or swimMapDownlinkDidRemoveAll(:objects:).

    Declaration

    Swift

    func swimMapDownlinkDidChange(downlink: MapDownlink)
  • Must only be called under objc_sync_enter(self)

    Declaration

    Swift

    private func sendBatchAfter(delay: NSTimeInterval)
  • Force a batch to be sent immediately, rather than waiting for the timeout to expire.

    Declaration

    Swift

    func sendBatch()
  • May only be called under objc_sync_enter(self)

    Declaration

    Swift

    private func recalcScore()
  • May only be called under objc_sync_enter(self)

    Declaration

    Swift

    private func networkConditionScore() -> Double
  • Decrement the reference count on the ServerMonitor for the given host, if any, and stop it monitoring if the refcount drops to 0.

    Declaration

    Swift

    public func stopMonitoring(host: String)
  • May only be called under objc_sync_enter(self)

    Declaration

    Swift

    private func currentNetworkCondition() -> SwimSwift.SwimNetworkConditionMonitor.NetworkCondition
  • May only be called under objc_sync_enter(self)

    Declaration

    Swift

    private func recalcNetworkCondition()
  • Call this to indicate that a network request timed out or failed. This drives the Healthy / Degraded stats.

    Declaration

    Swift

    public func networkErrorReceived()
  • Declaration

    Swift

    public func getMonitor(host: String) -> SwimSwift.SwimNetworkConditionMonitor.ServerMonitor?

    Return Value

    The ServerMonitor for the given host, if any. This does not change the reference count on the ServerMonitor.

  • Call this to indicate that a response was successfully received on this network. This drives the Healthy / Degraded stats.

    Declaration

    Swift

    public func networkResponseReceived()
  • Decrement the reference count on the given ServerMonitor, and stop it monitoring if the refcount drops to 0.

    Declaration

    Swift

    public func stopMonitoring(monitor: ServerMonitor)
  • Start monitoring the network to the specified host. This will start Reachability monitoring if necessary.

    Note that this is reference counted per host: you should pair your startMonitoring and stopMonitoring calls and the monitoring will be torn down once the last monitor for a given host is stopped.

    Declaration

    Swift

    public func startMonitoring(host: String, isWWLANAllowed: Bool = default) -> SwimSwift.SwimNetworkConditionMonitor.ServerMonitor
  • Stop monitoring everything.

    Declaration

    Swift

    public func stopMonitoringAll()
  • Must be called under objc_sync_enter(self)

    Declaration

    Swift

    private func extendRetryInterval()
  • Unlinks all downlinks and closes the network connection associated with this client.

    Declaration

    Swift

    public func close()
  •    let chatRoom = client.scope(node: "/chat/public", lane: "chat/room")
    

    Declaration

    Swift

    @warn_unused_result
    public func scope(node node: SwimUri, lane: SwimUri) -> <<error type>>

    Parameters

    node

    The destination service. Must contain a network authority component, as this specifies the destination host.

    lane

    The destination lane in the service at the given node.

    Return Value

    A new LaneScope bound to the given lane.

  • Authorizes all connections through this client with the provided recon credentials value.

       client.auth(credentials: Value(Slot("googleIdToken", "")))
    

    Declaration

    Swift

    @warn_unused_result
    public func auth(credentials credentials: SwimValue) -> <<error type>>

    Parameters

    credentials

    Might contain, for example, a .

  • let chat = client.scope(node: "/chat/public")
    

    Declaration

    Swift

    @warn_unused_result
    public func scope(node node: SwimUri) -> <<error type>>

    Parameters

    node

    The destination service.

    Return Value

    A new NodeScope bound to the service at the given node running on self.hostUri.

  • This is only intended for the initial load e.g. from the local database. It doesn’t handle conflicts with existing items already in this list (it assumes that this list is empty right now).

    Declaration

    Swift

    func loadValues(values: [SwimValue]) -> <<error type>>
  • Will be called after a batch of changes to ListDownlink.objects has been processed.

    In other words, this indicates the end of a batch of calls to swimListDownlink(:did{Insert,Move,Remove,Update}:atIndex:) or swimListDownlinkDidRemoveAll(:objects:).

    Declaration

    Swift

    func swimListDownlinkDidChangeObjects(downlink: ListDownlink)
  • Will be called whenever commands are received that will change ListDownlink.objects, and before those commands are processed.

    In other words, this indicates the start of a batch of calls to swimListDownlink(:did{Insert,Move,Remove,Update}:atIndex:) or swimListDownlinkDidRemoveAll(:objects:).

    Declaration

    Swift

    func swimListDownlinkWillChangeObjects(downlink: ListDownlink)